<%@ page import="java.util.List" %>
<%@ page import="com.example.demo_text.UserDAO" %>
<%@ page import="user.User" %>
<%@ page import="com.example.demo_text.EnrollmentDAO" %>
<%@ page import="com.example.demo_text.StudentEnrollment" %>
<%@ page import="com.example.demo_text.CourseDAO" %>
<%@ page import="com.example.demo_text.Course" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
  List<User> students = UserDAO.getAllStudents();
%>

<html>
<head>
  <title>学生选课管理</title>
  <style>
    /* 卡片和整体样式 */
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
      background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 40px 20px;
      color: #333;
    }

    .card {
      background: white;
      width: 100%;
      max-width: 600px;
      padding: 30px 25px;
      border-radius: 16px;
      box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
      transition: all 0.3s ease;
      text-align: center;
    }

    .card:hover {
      transform: translateY(-5px);
      box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    }

    h2 {
      text-align: center;
      margin-bottom: 24px;
      font-weight: 600;
      color: #374151;
    }

    .student-card {
      background: #f9fafb;
      border-radius: 12px;
      padding: 20px;
      margin-bottom: 20px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
      text-align: left;
    }

    .student-card h3 {
      margin: 0;
      font-size: 18px;
      color: #1f2937;
    }

    .course-list {
      margin: 10px 0;
      color: #6b7280;
    }

    .btn {
      display: inline-block;
      width: 100%;
      padding: 12px 20px;
      background-color: #d1ecf1;
      color: #15576b;
      border-radius: 8px;
      text-decoration: none;
      font-weight: 500;
      transition: background 0.3s, color 0.3s;
      margin-top: 10px;
    }

    .btn:hover {
      background-color: #aee2eb;
      color: #0f3d4d;
    }

    .back-link {
      display: block;
      text-align: center;
      margin-top: 30px;
      color: #3498db;
      text-decoration: underline;
      font-size: 14px;
    }

    .back-link:hover {
      color: #2980b9;
    }
  </style>
</head>
<body>

<div class="card">
  <h2>📚 学生选课管理</h2>
  <p style="margin-bottom: 20px;">每位学生都显示，点击“编辑”可查看或修改其选课记录</p>

  <% for (User student : students) { %>
  <%
    int userId = student.getId();
    List<StudentEnrollment> enrollments = EnrollmentDAO.getEnrollmentsByUserId(userId);
  %>
  <div class="student-card">
    <h3><%= student.getUsername() %></h3>
    <ul class="course-list">
      <% if (enrollments.isEmpty()) { %>
      <li>（暂无选课）</li>
      <% } else {
        for (StudentEnrollment se : enrollments) {
          Course c = CourseDAO.getCourseById(se.getCourseId());
      %>
      <li><%= c.getName() %></li>
      <% } } %>
    </ul>
    <a href="editEnrollment.jsp?userId=<%= student.getId() %>" class="btn">编辑选课</a>
  </div>
  <% } %>

  <a href="AdmitHome.jsp" class="back-link">返回管理员主页</a>
</div>

</body>
</html>
